package com.yangle.frame.common.utils;

import com.yangle.frame.admin.entity.BaseEntity;
import tk.mybatis.mapper.entity.Example;

import java.lang.reflect.Field;

/**
 * Created by yangle on 2018/6/3.
 */
public class MapperUtils {
    public static Example getExampleByClass(Class clazz, BaseEntity entity){
        Example example=new Example(clazz);
        Example.Criteria criteria = example.createCriteria();
        for (Field field:clazz.getDeclaredFields()){
            try {
                field.setAccessible(true);
                Object o = field.get(entity);
                if(o!=null){
                    criteria.andLike(field.getName(),"%"+o.toString()+"%");
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return example;
    }
}
